<?php
$g4_path = "../"; 
require_once ($g4_path.'common.php');

$title = "학생 수업 정보";
$menu = 3;
require_once ('./admin.head.php');
require_once ('./admin.lib.php');

$_GET['year'] = isset($_GET['year'])? $_GET['year'] : date('Y');
$_GET['month'] = isset($_GET['month'])? $_GET['month'] : date('n');

$where = '';
if(isset($_GET['name'])) {
$where = "AND mb_name like '%".addslashes($_GET['name'])."%'";
}
$limitSQL = getLimit();

$countSql = "SELECT count(1) from (SELECT c.no from g4_member m, course_order o,course c WHERE o.student = m.mb_no  AND c.year = {$_GET['year']} AND c.month = {$_GET['month']} AND c.no = o.course $where GROUP by o.student) a";
$dataSql = "SELECT mb_no, mb_name, mb_tel, mb_hp FROM g4_member g, course_order o, course c WHERE o.student = g.mb_no  AND c.year = {$_GET['year']} AND c.month = {$_GET['month']} AND c.no = o.course $where Group by o.student $limitSQL";
$page = isset($_GET['page'])? $_GET['page']: 1;
list($totalCount) = mysql_fetch_array(mysql_query($countSql));
$count = $totalCount - ($page - 1) * 20;
$res = mysql_query($dataSql);

$data = array();
while($temp = mysql_fetch_assoc($res)) {
        $sql = "SELECT count(1) from course_order WHERE student = {$temp['mb_no']}";
        list($temp['courseCount']) = mysql_fetch_array(mysql_query($sql));
        $sql = "SELECT w_mon+w_tue+w_wed+w_thu+w_fri+w_sat from course c, course_order o WHERE o.student = {$temp['mb_no']}  AND c.year = {$_GET['year']} AND  c.month = {$_GET['month']} AND c.no = o.course";
        list($temp['week']) = mysql_fetch_array(mysql_query($sql));
        if(!$temp['week']) $temp['week'] = 0;
        $temp['month'] = $temp['week'] * 4;
        $temp['count'] = $count--;
        $data[] = $temp;
}
$thisYear = date('Y');
for($i = 2008; $i <= $thisYear; $i++) {
        $years[$i]= array('y' => "{$i}년");
        if($i == $_GET['year']) {
            $years[$i]['s'] = 'selected="selected"';
        }
}

$monthSelected = array($_GET['month']=>'selected="selected"');

$pager = getPager($totalCount); 
$tpl->define('basic',"studentCourseManage.html");
$tpl->print_('basic');

require_once('admin.foot.php');
